local hx__sanyin = fk.CreateSkill {
  name = "hx__sanyin",
}

local spec = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    local targets = table.filter(player.room:getAlivePlayers(), function(p)
      return not p.dying and not p.dead
    end)
    if player:hasSkill(hx__sanyin.name) and #targets > 0 then
      event:setCostData(self, {to = targets})
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local tos = event:getCostData(self).to
    local to = player.room:askToChoosePlayers(player,{
      targets = tos,
      min_num = 1,
      max_num = 1,
      skill_name = hx__sanyin.name,
      prompt = "三阴：你可以令一名不处于濒死状态的角色回复一点体力或摸两张牌",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {to = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).to
    local choice = room:askToChoice(tos[1], {
      choices = {"回复一点体力", "摸两张牌"},
      prompt = "你可以执行一项",
      skill_name = hx__sanyin.name,
    })
    if choice == "回复一点体力" then
      room:recover({
        who = tos[1],
        num = 1,
        skillName = hx__sanyin.name
      })
    elseif choice == "摸两张牌" then
      tos[1]:drawCards(2, hx__sanyin.name)
    end
  end,
}

hx__sanyin:addEffect(fk.Death, spec)
hx__sanyin:addEffect(fk.EnterDying, spec)
hx__sanyin:addEffect(fk.AfterDying, spec)


return hx__sanyin